package view;

import java.awt.Event;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

import model.CModel;

public class MenuBar extends JMenuBar implements ActionListener {

	private CModel model;
	private JMenuItem clearMI, exitMI;
	
	public MenuBar( CModel model ) {
		this.model = model;
	}
	
	public JMenuBar GetMenuBar() {

		JMenu fileMenu = new JMenu("Filer");

		clearMI = new JMenuItem("Ny");
		clearMI.setAccelerator(KeyStroke.getKeyStroke('C', Event.ALT_MASK));
		clearMI.addActionListener(this);

		fileMenu.add(clearMI);

		exitMI = new JMenuItem("Afslut");
		exitMI.setAccelerator(KeyStroke.getKeyStroke('X', Event.ALT_MASK));
		exitMI.addActionListener(this);

		fileMenu.add(exitMI);
		add(fileMenu);
		
		return this;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		Object source = e.getSource();

		if (source == clearMI)
			model.clearAll();
		else if (source == exitMI)
			System.exit(0);

	}
	
}
